package com.hmall.search.web;

import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.PageResult;
import com.hmall.search.pojo.SearchParam;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService service;

    @GetMapping("/suggestion")
    public List<String> findSuggestionKey(@RequestParam("key") String key){
        return service.findItemBySuggestionKey(key);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filter(@RequestBody SearchParam searchParam){
        return service.filter(searchParam);
    }

    @PostMapping("/list")
    public PageResult<ItemDoc> findItemByParam(@RequestBody SearchParam searchParam){
        return service.findItemByParam(searchParam);
    }
}
